package com.mgs.tagger.appdata
{
	import com.mgs.tagger.appdata.dto.DirectoryDTO;
	import com.mgs.tagger.appdata.dto.FileItemDTO;
	import com.mgs.tagger.appdata.dto.TagDTO;
	import com.mgs.tagger.appdata.dto.WorkspaceDTO;
	import com.mgs.tagger.log.Level;
	import com.mgs.tagger.log.Logger;
	
	import flash.utils.Dictionary;

	public class FileItemResolver
	{
		private var mapNameFileItem:Dictionary = new Dictionary();
		
		private var workspace:WorkspaceDTO;
		
		public function FileItemResolver(workspace:WorkspaceDTO)
		{
			this.workspace = workspace;
			// build map based on tags
			for each(var tag:TagDTO in workspace.tags){
				for each(var f:FileItemDTO in tag.files){
					mapNameFileItem[f.filename] = f;
				}
			}
		}
		
		public function resolveFileItem(name:String):FileItemDTO{
			if(mapNameFileItem[name]){
				return mapNameFileItem[name];
			}
			var dto:FileItemDTO = new FileItemDTO();
			mapNameFileItem[name] = dto;
			dto.filename = name;
			dto.tags = new Vector.<TagDTO>();
			return dto;
		}
		
		
	}
}